package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Area;
import cn.wolfcode.trip.base.domain.Region;
import cn.wolfcode.trip.base.mapper.AreaMapper;
import cn.wolfcode.trip.base.query.AreaQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IAreaService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaServiceImpl implements IAreaService {

    @Autowired
    private AreaMapper areaMapper;


    @Override
    public List<Area> selectAreaByParentId(QueryObject qo) {
        return areaMapper.selectByParentId(qo);
    }

    @Override
    public void saveOrUpdate(Area area) {
        if (area.getId()==null){
            areaMapper.insert(area);
        }else{
            areaMapper.updateByPrimaryKey(area);
        }
    }

    @Override
    public List<Area> list() {
        return areaMapper.selectAll();
    }

    @Override
    public void deleteById(Long id) {
        areaMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo query(AreaQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Area> list = areaMapper.selectForList(qo);
        return new PageInfo(list);
    }

}
